package com.atu.atugra.controller;

/**
 * @Author: 陈焕科
 * @DateTime: 2025-02-13 11:06
 */
import com.atu.atugra.constant.AppHttpCodeEnum;
import com.atu.atugra.service.QiniuService;
import com.atu.atugra.tools.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/qiniu")
@Slf4j
public class QiniuController {
    @Autowired
    private QiniuService qiniuService;
    @PostMapping("/uploadImg")
    public CommonResult uploadImg(@RequestBody MultipartFile file, HttpServletRequest request) {
        try {
            String fileUrl=qiniuService.saveImage(file,request);
//            log.error("上传文件");
            return CommonResult.okResult(fileUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.failed(AppHttpCodeEnum.ERROR);
    }
}



